package com.gagakuai.engine.delegate.event;

import com.gagakuai.engine.exception.ActivitiIllegalArgumentException;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/*
 * @program: common-starters
 * @description: 事件类型
 * @author: houhong
 * @create: 2023-01-02 21:14
 */
public enum ActivitiEventType {

    ENTITY_CREATED;

    public static final ActivitiEventType[] EMPTY_ARRAY = new ActivitiEventType[]{};

    public static ActivitiEventType[] getTypesFromString(String string) {
        List<ActivitiEventType> result = new ArrayList<>();
        if (string != null && !string.isEmpty()) {

            String[] split = StringUtils.split(string, ",");

            for (String typeName : split) {

                boolean found = false;

                for (ActivitiEventType type : values()) {

                    if (typeName.equals(type.name())) {
                        result.add(type);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    throw new ActivitiIllegalArgumentException("Invalid event-type: " + typeName);
                }
            }
        }

        return result.toArray(EMPTY_ARRAY);
    }
}